package wang.j100.uc.module.system.api.user;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import wang.j100.uc.framework.common.util.object.BeanUtils;
import wang.j100.uc.framework.datapermission.core.util.DataPermissionUtils;
import wang.j100.uc.module.system.api.user.dto.AdminUserRespDTO;
import wang.j100.uc.module.system.dal.dataobject.user.AdminUserDO;
import wang.j100.uc.module.system.service.user.AdminUserService;

import java.util.Collection;
import java.util.List;

/**
 * Admin 用户 API 实现类
 *
 * @author 用户中心
 */
@Service
public class AdminUserApiImpl implements AdminUserApi {

    @Resource
    private AdminUserService userService;

    @Override
    public AdminUserRespDTO getUser(Long id) {
        AdminUserDO user = userService.getUser(id);
        return BeanUtils.toBean(user, AdminUserRespDTO.class);
    }

    @Override
    public List<AdminUserRespDTO> getUserList(Collection<Long> ids) {
        return DataPermissionUtils.executeIgnore(() -> { // 禁用数据权限。原因是，一般基于指定 id 的 API 查询，都是数据拼接为主
            List<AdminUserDO> users = userService.getUserList(ids);
            return BeanUtils.toBean(users, AdminUserRespDTO.class);
        });
    }

    @Override
    public void validateUserList(Collection<Long> ids) {
        userService.validateUserList(ids);
    }

}
